package com.xinke.component.web.web.core.filter;

import cn.hutool.core.util.StrUtil;
import com.xinke.component.web.web.config.WebProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.http.HttpServletRequest;

/**
 * Description:
 *  过滤 /admin-api、/app-api 等 API 请求的过滤器
 * @Author yzx
 * @Create 2025/3/13 00:42
 * @Version 1.0
 */
@RequiredArgsConstructor
@Slf4j
public abstract class ApiRequestFilter extends OncePerRequestFilter {

    protected final WebProperties webProperties;

    @Override
    protected boolean shouldNotFilter(HttpServletRequest request) {
        log.debug("shouldNotFilter: {}", request.getRequestURI());
        // 只过滤 API 请求的地址
        String apiUri = request.getRequestURI().substring(request.getContextPath().length());
        return !StrUtil.startWithAny(apiUri, webProperties.getAdminApi().getPrefix(), webProperties.getAppApi().getPrefix());
    }

}